#!/bin/bash
while :
do
	(time=`date +%F-%H:%M:%S`
	scan=`nc -z 192.168.0.189 21`
	if (($?==0));then
		echo "${time} ${scan}" >>/var/log/ftp_server_monitor.log
		echo -e "\e[1;32m ftp server is up\e[0m" 
		echo "${time} ${scan}" 
	else 
		echo "${time} ftp server is down" >>/var/log/ftp_server_monitor.log
		echo -e "\e[1;31m Warnning ,ftp server is down\e[0m"
	fi)&
	sleep 1
		down_time=`cat /var/log/ftp_server_monitor.log |egrep "down$" |wc -l`
		if (( $down_time < 60 ));then
        		printf ""宕机时间总共:" %4.2f"秒"\n" $dowm_time
		else
        		min=`echo "scale=2;${down_tiem}/60" |bc`
        		printf ""宕机时间总共:" %4.2f"分钟"\n" $min
		fi
done
